var app = getApp(), siteinfo = require("../../../siteinfo.js");

Page({
    data: {
        userInfo: {},
        hasUserInfo: !1,
        getmsg: "发送验证码",
        num: 0,
        frequency: 0
    },
    onLoad: function(e) {
        var o = this;
        console.log(app), wx.hideShareMenu();
        var a = e.status;
        o.setData({
            status: a
        }), app.util.request({
            url: "entry/wxapp/getSystem",
            cachetime: "0",
            success: function(e) {
                console.log("这是系统设置"), console.log(e), o.setData({
                    system: e.data
                });
            }
        }), app.getUserInfo(function(e) {
            console.log(e), o.setData({
                userInfo: e,
                user_id: e.id
            }), o.refresh();
        });
    },
    refresh: function(e) {
        var o = this;
        app.util.request({
            url: "entry/wxapp/GetSponsor",
            cachetime: "0",
            data: {
                user_id: o.data.userInfo.id
            },
            success: function(e) {
                console.log("这是获取主办方资料"), console.log(e), 0 == e.data ? o.setData({
                    name: "",
                    phone: "",
                    logo: "",
                    info: "",
                    sponsor: 2
                }) : o.setData({
                    name: e.data.name,
                    phone: e.data.tel,
                    logo: e.data.logo,
                    info: e.data.details.replace("↵", "\n"),
                    sponsor: 1,
                    sponsor_id: e.data.id
                });
            }
        }), app.util.request({
            url: "entry/wxapp/url",
            cachetime: "0",
            success: function(e) {
                console.log("这是网址"), console.log(e), o.setData({
                    url: e.data
                });
            }
        });
    },
    img_array: function(e) {
        var a = this;
        a.setData({
            addmuban: !0
        });
        var t = siteinfo.siteroot;
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                wx.showToast({
                    icon: "loading",
                    title: "正在上传"
                });
                var o = e.tempFilePaths[0];
                t = t + "?i=" + a.data.system.uniacid + "&c=entry&a=wxapp&do=Upload&m=zh_gjhdbm", 
                wx.uploadFile({
                    url: t,
                    filePath: o,
                    name: "upfile",
                    formData: null,
                    success: function(e) {
                        console.log(e), a.setData({
                            logo: e.data
                        });
                    }
                });
            }
        });
    },
    code: function(e) {
        var o = e.detail.value;
        this.setData({
            code: o
        });
    },
    formSubmit: function(e) {
        var o = this;
        console.log(e);
        var a = o.data.user_id, t = e.detail.value.name, s = e.detail.value.phone, n = e.detail.value.info, l = o.data.num, i = o.data.code, c = o.data.system;
        n = n.replace("\n", "↵");
        var u = o.data.logo;
        console.log(a), console.log(t), console.log(s), console.log(n), console.log(u);
        var r = "";
        if ("" == t ? r = "请输入名字" : "" == u ? r = "请上传logo" : "" == s ? r = "请输入手机号" : "" == n ? r = "请输入主办方简介" : 1 == c.is_dxyz && (0 == l ? r = "请进行短信验证" : 0 != l && i != l && (r = "短信验证码错误")), 
        "" != r) wx.showModal({
            title: "温馨提示",
            content: r
        }); else {
            var d = o.data.sponsor;
            console.log(d);
            var p = o.data.frequency;
            0 == p ? (o.setData({
                frequency: p + 1
            }), 2 == d ? app.util.request({
                url: "entry/wxapp/savesponsor",
                cachetime: "0",
                data: {
                    user_id: a,
                    name: t,
                    logo: u,
                    tel: s,
                    details: n
                },
                success: function(e) {
                    console.log("这是上传主办方资料"), console.log(e), 1 == o.data.status ? (wx.showToast({
                        title: "上传成功",
                        icon: "success",
                        duration: 2e3
                    }), setTimeout(function() {
                        wx.redirectTo({
                            url: "../fabu/fabu"
                        });
                    }, 2e3)) : (wx.showToast({
                        title: "上传成功",
                        icon: "success",
                        duration: 2e3
                    }), setTimeout(function() {
                        wx.navigateBack({
                            delta: 1
                        });
                    }, 2e3));
                }
            }) : app.util.request({
                url: "entry/wxapp/savesponsor",
                cachetime: "0",
                data: {
                    id: o.data.sponsor_id,
                    user_id: a,
                    name: t,
                    logo: u,
                    tel: s,
                    details: n
                },
                success: function(e) {
                    console.log("这是修改主办方资料"), console.log(e), 1 == e.data && (wx.showToast({
                        title: "修改成功",
                        icon: "success",
                        duration: 2e3
                    }), setTimeout(function() {
                        wx.navigateBack({
                            delta: 1
                        });
                    }, 2e3));
                }
            })) : setTimeout(function() {
                wx.navigateBack({
                    delta: 1
                });
            }, 2e3);
        }
    },
    phone: function(e) {
        var o = e.detail.value;
        this.setData({
            phone: o
        });
    },
    getPhoneNumber: function(e) {
        console.log(e.detail.errMsg), console.log(e.detail.iv), console.log(e.detail.encryptedData);
        var o = this;
        console.log(app.session_key), app.util.request({
            url: "entry/wxapp/jiemi",
            cachetime: "0",
            data: {
                sessionKey: app.session_key,
                iv: e.detail.iv,
                data: e.detail.encryptedData
            },
            success: function(e) {
                console.log("这是解密手机号"), console.log(e), o.setData({
                    phone: e.data.phoneNumber
                });
            }
        });
    },
    sendmessg: function(e) {
        var o = this;
        console.log(o.data);
        var a = o.data.phone;
        if ("" == a || null == a) wx.showToast({
            title: "请输入手机号",
            icon: "",
            image: "",
            duration: 2e3,
            mask: !0,
            success: function(e) {},
            fail: function(e) {},
            complete: function(e) {}
        }); else {
            for (var t = "", s = 0; s < 6; s++) t += Math.floor(10 * Math.random());
            console.log(t), app.util.request({
                url: "entry/wxapp/Sms2",
                cachetime: "0",
                data: {
                    code: t,
                    tel: a
                },
                success: function(e) {
                    console.log(e);
                }
            }), o.setData({
                num: t
            });
            var n = 60, l = setInterval(function() {
                o.setData({
                    getmsg: n + "s后重新发送",
                    send: !0
                }), --n <= 0 && (clearInterval(l), o.setData({
                    getmsg: "获取验证码",
                    send: !1,
                    num: 0
                }));
            }, 1e3);
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});